<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>6.270 - JoyOS: kern/thread.h File Reference</title>
	<link href="main.css" media="screen" rel="Stylesheet" type="text/css"/>
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>  
<body>
	<div id="header">
		<div id="headerb">
		<div id="headtext">
			<span class="titletext">AUTONOMOUS ROBOT DESIGN COMPETITION</span>
			6.270
		</div>
		<div class="mainmenu">
			<a href="http://web.mit.edu/6.270/www">Home</a>
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/about/">About</a> 
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/sponsors/">Sponsors</a>
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/contests/">Past Contests</a> 
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/contestants/">Contestant Information</a>
		</div>
	</div>
	</div>

<div class="maincontent">
<!-- Generated by Doxygen 1.5.1 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    <li><a href="globals.html"><span>Globals</span></a></li>
  </ul></div>
<h1>kern/thread.h File Reference</h1>Thread management. <a href="#_details">More...</a>
<p>
<code>#include &lt;setjmp.h&gt;</code><br>
<code>#include &lt;stdint.h&gt;</code><br>
<code>#include &lt;config.h&gt;</code><br>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#23d2156b2f1b46c63e6ba11745b65468">init_thread</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#af712cb0affdbd884c0df1d668dd2615">start_sched</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#c48128e72b303ea22d8ec641a9516b15">schedule</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#cf110e07a416e636772e6ba9c3246ebb">suspend</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#2de3392334d71c626aa4464be8895df6">resume</a> (struct thread *t)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#540b459ff4f07cb40b580310b0d1c6f6">pause</a> (uint16_t ms)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#7cb51f5c2b5cad3766f19eb69c92793b">yield</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#6f255d924f7a6bb2c4be0c8c2f2d9ce3">exit</a> (int)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">uint8_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#9fce5f6854cb440b023e126ac7e692de">create_thread</a> (int(*func)(), uint16_t stacksize, uint8_t priority, char *name)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#ee01d3a42fbcda425a19cbc4bd0194cd">halt</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">uint32_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#5d9b297546ac7a15e98b7adac51e98d0">get_time</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="thread_8h.html#90f429f328c031385387ec51e10c8adc">dump_threadstates</a> ()</td></tr>

</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
JoyOS includes a round-robbin pre-emptive scheduler, with a system tick of 1ms. <hr><h2>Function Documentation</h2>
<a class="anchor" name="9fce5f6854cb440b023e126ac7e692de"></a><!-- doxytag: member="thread.h::create_thread" ref="9fce5f6854cb440b023e126ac7e692de" args="(int(*func)(), uint16_t stacksize, uint8_t priority, char *name)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint8_t create_thread           </td>
          <td>(</td>
          <td class="paramtype">int(*)()&nbsp;</td>
          <td class="paramname"> <em>func</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint16_t&nbsp;</td>
          <td class="paramname"> <em>stacksize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint8_t&nbsp;</td>
          <td class="paramname"> <em>priority</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char *&nbsp;</td>
          <td class="paramname"> <em>name</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Create a new thread. This routine will setup a new thread that will enter in 'func' and return immediately. When 'func' returns, the new thread will terminate (via exit).<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>func</em>&nbsp;</td><td>Entry point of thread. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>stacksize</em>&nbsp;</td><td>Size (in bytes) of new thread. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>priority</em>&nbsp;</td><td>Priority of new thread. 0 = highest, 255 = lowest </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>name</em>&nbsp;</td><td>Name of thread, used for debugging.</td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Thread ID of the new thread. </dd></dl>

</div>
</div><p>
<a class="anchor" name="90f429f328c031385387ec51e10c8adc"></a><!-- doxytag: member="thread.h::dump_threadstates" ref="90f429f328c031385387ec51e10c8adc" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void dump_threadstates           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Output to the UART the state of every thread. 
</div>
</div><p>
<a class="anchor" name="6f255d924f7a6bb2c4be0c8c2f2d9ce3"></a><!-- doxytag: member="thread.h::exit" ref="6f255d924f7a6bb2c4be0c8c2f2d9ce3" args="(int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void exit           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Terminate and exit the current thread. This will free the thread's stack space, but not any of it's dynamically allocated memory (malloc). 
</div>
</div><p>
<a class="anchor" name="5d9b297546ac7a15e98b7adac51e98d0"></a><!-- doxytag: member="thread.h::get_time" ref="5d9b297546ac7a15e98b7adac51e98d0" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t get_time           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Return the number of milliseconds elapsed since startup. 
</div>
</div><p>
<a class="anchor" name="ee01d3a42fbcda425a19cbc4bd0194cd"></a><!-- doxytag: member="thread.h::halt" ref="ee01d3a42fbcda425a19cbc4bd0194cd" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void halt           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Stop everything. 
</div>
</div><p>
<a class="anchor" name="23d2156b2f1b46c63e6ba11745b65468"></a><!-- doxytag: member="thread.h::init_thread" ref="23d2156b2f1b46c63e6ba11745b65468" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void init_thread           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Initialize multithreading. Should not be called by user. 
</div>
</div><p>
<a class="anchor" name="540b459ff4f07cb40b580310b0d1c6f6"></a><!-- doxytag: member="thread.h::pause" ref="540b459ff4f07cb40b580310b0d1c6f6" args="(uint16_t ms)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void pause           </td>
          <td>(</td>
          <td class="paramtype">uint16_t&nbsp;</td>
          <td class="paramname"> <em>ms</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Pause a thread for 'ms' milliseconds. The calling thread will give up the processor until time expires. If interrupts are disabled, a busy loop will be used. The pause is best-effort and may last several milliseconds longer than specified. If threads pause frequently for short periods of time (1-4ms, depending) thread starvation may occur.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>ms</em>&nbsp;</td><td>Milliseconds to pause. </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="2de3392334d71c626aa4464be8895df6"></a><!-- doxytag: member="thread.h::resume" ref="2de3392334d71c626aa4464be8895df6" args="(struct thread *t)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void resume           </td>
          <td>(</td>
          <td class="paramtype">struct thread *&nbsp;</td>
          <td class="paramname"> <em>t</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Load a thread and run it. Should not be called by user.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>t</em>&nbsp;</td><td>Thread to be run. </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="c48128e72b303ea22d8ec641a9516b15"></a><!-- doxytag: member="thread.h::schedule" ref="c48128e72b303ea22d8ec641a9516b15" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void schedule           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Schedule a thread to run. Should not be called by user. 
</div>
</div><p>
<a class="anchor" name="af712cb0affdbd884c0df1d668dd2615"></a><!-- doxytag: member="thread.h::start_sched" ref="af712cb0affdbd884c0df1d668dd2615" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void start_sched           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Jump to scheduler, nuke the kstack. Should not be called by user. 
</div>
</div><p>
<a class="anchor" name="cf110e07a416e636772e6ba9c3246ebb"></a><!-- doxytag: member="thread.h::suspend" ref="cf110e07a416e636772e6ba9c3246ebb" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void suspend           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Suspend the current thread and call the scheduler. Should not be called by user. 
</div>
</div><p>
<a class="anchor" name="7cb51f5c2b5cad3766f19eb69c92793b"></a><!-- doxytag: member="thread.h::yield" ref="7cb51f5c2b5cad3766f19eb69c92793b" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void yield           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Give up the processor to another thread until rescheduled. 
</div>
</div><p>
</div>
<div class="maincontent">
	<div class="footer centre">
		<hr>
		Generated on Tue Jan 29 23:17:08 2008 by&nbsp;<a href="http://www.doxygen.org/index.html">Doxygen</a> 1.5.1<br/>
		6.270 Staff, 2008 | 
		<a href="mailto:6.270-organizers@mit.edu">Contact Us</a> | 
		<a href="http://web.mit.edu">MIT</a>
	</div>
</div>
</body>
</html>
